package cn.smxy.user.controller;

import cn.smxy.param.CampusRemoveParam;
import cn.smxy.param.CampusSearchParam;
import cn.smxy.param.CollegeSearchParam;
import cn.smxy.param.UserIdParam;
import cn.smxy.pojo.Campus;
import cn.smxy.user.service.CampusService;
import cn.smxy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/campus")
public class CampusController {

    @Autowired
    private CampusService campusService;

    /**
     * 校园学生认证接口
     * @param campus
     * @param result
     * @return
     */
    @PostMapping("/check")
    public R check(@RequestBody @Validated Campus campus, BindingResult result){
        if(result.hasErrors()) {
            return R.fail("参数错误，认证失败");
        }
        return campusService.check(campus);
    }

    /**
     * 查看校园认证详情接口
     * @param userIdParam
     * @param result
     * @return
     */
    @PostMapping("/view")
    public R view(@RequestBody @Validated UserIdParam userIdParam,BindingResult result) {
        if(result.hasErrors()) {
            return R.fail("参数异常，查看失败");
        }
        return campusService.view(userIdParam);
    }

    // TODO:管理员模块

    /**
     * 分页展示校园认证接口
     * @param campusSearchParam
     * @return
     */
    @PostMapping("/page")
    public R page(@RequestBody CampusSearchParam campusSearchParam) {
        return campusService.page(campusSearchParam);
    }

    /**
     * 校园认证批量删除接口
     *
     * @param campusRemoveParam
     * @return
     */
    @PostMapping("/remove/batch")
    public R campusRemoveBatch(@RequestBody CampusRemoveParam campusRemoveParam) {
        return campusService.campusRemoveBatch(campusRemoveParam);
    }
}
